const baseUrl = "http://juanxincai.zyxj888.top/";
import axios from "axios";
const request = (url, method, data) => {
  return new Promise((resolve, reject) => {
    if (method === "GET") {
      axios({
        method: method,
        url: baseUrl + url,
        params: data,
      })
        .then((res) => {
          resolve(res.data);
        })
        .catch((err) => {
          reject(err.data); //失败
        });
    } else if (method === "POST") {
      axios({
        method: method,
        url: baseUrl + url,
        data: qs.stringify(data),
      })
        .then((res) => {
          if (res.data.status === 1) {
            resolve(res.data);
          } else {
            resolve(res.data);
          }
        })
        .catch((err) => {
          reject(err.data); //失败
        });
    }
  });
};
export default request;
